#ifndef OBJECTBROWSERVIEW_H
#define OBJECTBROWSERVIEW_H

#include <scene/scene.h>
#include <scene/sector.h>
#include <scene_editor/sceneeditor.h>
#include <object_browser/objectstreemodel.h>
#include <gfx/mesh.h>
#include <scene.h>
#include <physics/physicsworld.h>
#include <timeframewidget.h>

#include <baseview.h>
#include <QAction>
#include <QTreeView>
#include <QSplitter>
#include <QPoint>


class ObjectOverviewTreeModel;
class ObjectBrowserView : public BaseView
{
  Q_OBJECT
public:
  enum Action
  {
    Action_ObjectSelect,
    Action_ObjectImport,
    Action_ObjectRename,
    Action_ObjectRemove,

    Action_GroupRename,
    Action_GroupRemove,

    Action_COUNT
  };

  enum NodeActions
  {
    NodeAction_Rename,
    NodeAction_ChangeMaterial,
    NodeAction_ShowMaterial,
    NodeAction_COUNT
  };

private:
  QTreeView     *_objectsTree;
  QTreeView     *_nodesTree;
  QSplitter     *_splitter;
  SceneEditorComponent* _editorComponent;
  SceneEditorWidget*  _editor;
  ceNode*       _currentNode;

//  GroupNode*    _groupNode;
  SceneObject*  _currentObject;
  TimeFrameWidget*  _timeFrameWidget;

  ceSector*     _sectorContent;

  cmPhysicsWorld* _physicsWorld;
  QList<btRigidBody*> _physicBodies;


  QSlider*      _lodSlider;
  ManualLevelOfDetailSolver*  _manualSolver;

  ObjectOverviewTreeModel*  _nodesModel;
  ObjectsTreeModel*         _objectsModel;

  QAction*                  _actions[Action_COUNT];
  QAction*                  _nodeActions[NodeAction_COUNT];
  ObjectManager*            _manager;

  void InitActions ();
  void InitGUI ();
  void CreateOrUpdateBoundingBoxMesh(const ceBoundingBox& bbox);

private slots:
  void nodeActivated (const QModelIndex& index);
  void nodeClicked(const QModelIndex &index);
  void objectActivated (const QModelIndex& index);
  void SelectOverviewNode (ceNode* entity);

  void RenameActivated ();
  void ChangeMaterialActivated ();
  void ShowMaterialActivated ();
  void ContextMenuRequest (const QPoint& point);

  void MouseMoved (float h, float v);
  void EditorChanged ();

  void LODSliderChanged (int value);
  void NodeSelectionChanged (const QModelIndex& newIndex, const QModelIndex& oldIndex);

  void ObjectContextMenu (const QPoint &point);
  void ObjectSelectionChanged (const QModelIndex& newIndex, const QModelIndex& oldIndex);

  void ObjectSelect ();
  void ObjectAdd ();
  void ObjectRename ();
  void ObjectRemove ();
  void GroupRename ();
  void GroupRemove ();


  void Save ();
  void SaveAll ();

public:
  ObjectBrowserView(ObjectManager* manager, QWidget* parent = 0);
  void ConnectSignals();
  void CreateMenu(MainWindow *mainWindow);
  void CreateScene ();

public slots:
  void Open (const QString& filename);


};

#endif // OBJECTBROWSERVIEW_H
